package com.jxsm.controller;

import com.jxsm.pojo.ContractProduct;
import com.jxsm.pojo.Factory;
import com.jxsm.service.ContractProductService;
import com.jxsm.service.FactoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/11/2.
 */
@Controller
public class ContractProductController extends BaseController {
    @Autowired
    private ContractProductService contractProductService;
    @Autowired
    private FactoryService factoryService;

    @RequestMapping("/cargo/contract/productCreate.action")
    public String productCreate(String contractId, Map<String,Object>map){
        //传递合同的id；
        map.put("contractId",contractId);

        //获取启动状态的厂家名称；
        List<Factory> factoryList=factoryService.list();
        map.put("factoryList",factoryList);

        Map<String,Object> paraMap = new HashMap();
        paraMap.put("contractId",contractId);

        //获取某个合同下的 货物列表
        List<ContractProduct>contractProducts =contractProductService.find(paraMap);
        System.out.println(contractProducts);
        map.put("contractProduct",contractProducts);
        return "/cargo/contracrProduct/productCreate.jsp";
    }
    @RequestMapping("/cargo/contract/toinsertproduct.action")
    public String insert (ContractProduct contractProduct,Map<String ,Object>map){
        map.put("contractId",contractProduct.getContractId());
        contractProductService.insert(contractProduct);
        return "redirect:/cargo/contract/productCreate.action";
    }
    @RequestMapping("/cargo/contract/toupdateProduct.action")
    public String toupdateProduct(String id,Map<String,Object>map){
        //回显修改的信息
        map.put("products",contractProductService.get(id));
        System.out.println(contractProductService.get(id));

        //获取启动状态的厂家名称；
        List<Factory> factoryList=factoryService.list();
        map.put("factoryList",factoryList);

        return  "\\cargo\\contracrProduct\\contractProductUpdate.jsp";
    }
    @RequestMapping("/cargo/contract/toinsert.action")
    public String save(ContractProduct contractProduct){
      contractProductService.update(contractProduct);
        return "/cargo/contracrProduct/productCreate.jsp";
    }
    @RequestMapping("/cargo/contract/todeleteProduct.action")
    public String delete(String id,String contractId,Map<String,Object>map){
        map.put("contractId",contractId);
        contractProductService.deleteById(id);
        return "redirect:/cargo/contract/productCreate.action";
   }
}
